<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 240px;
            height: 240px;
            background-color: #ddd;
            position: fixed;
            right: 0;
            bottom: 0;
        }

        span {
            float: right;
            background-color: #f00;
            padding: 10px;
            color: #fff;

            cursor: pointer;
        }
    </style>
</head>

<body>

    <div>
        <span>X</span>
        <p>10s之后自动关闭</p>
    </div>


    <script>


        // 点X关闭    盒子隐藏
        var oSpan = document.querySelector('span');
        var oBox = document.querySelector('div');
        var oP = document.querySelector('p');

        oSpan.onclick = function () {
            oBox.style.display = 'none';
        }

        // 10s倒计时   盒子隐藏 
        var count = 10;

        var t = setInterval(function () {
            count--;
            oP.innerHTML = count + 's之后自动关闭';
            // 判断 0
            if (count < 0) {
                oBox.style.display = 'none';
                // 清除定时器
                clearInterval(t);

            }
        }, 500)





    </script>

</body>

</html>